package com.nunbey.lingxi.activities.sub;

import android.app.AlertDialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.nunbey.lingxi.R;
import com.nunbey.lingxi.activities.LoginActivity;
import com.nunbey.lingxi.lincat.activityinit.BaseActivity;
import com.nunbey.lingxi.lincat.dialog.AlertDialogCreator;

public class SubBaseActivity extends BaseActivity {
    /**
     * @description 加载actionBar
     * @param menu
     * @return
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater menuInflater = this.getMenuInflater();
        menuInflater.inflate(R.menu.action_bar,menu);
        return true;
    }

    /**
     * @description actionBar响应
     * @param item
     * @return
     */
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        super.onOptionsItemSelected(item);
        if(item.getItemId()==R.id.action_bar_startWebVersion){
            String webUri = "http://81.70.236.177:9781/#/patientecg";
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setData(Uri.parse(webUri));
            startActivity (intent);
        }
        if(item.getItemId()==R.id.action_bar_exitLogin){
            AlertDialog alertDialog = AlertDialogCreator.getQueryDialog(this, "退出询问"
                    , "您确定要退出登录?", "确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Intent intent = new Intent(SubBaseActivity.this,LoginActivity.class);
                            //清空所有活动栈，让新启动的活动成为唯一根活动
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            SubBaseActivity.this.startActivity(intent);
                        }
                    }, "取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    });
            alertDialog.show();
        }
        if(item.getItemId()==R.id.action_bar_downLoadApk){
            String webUri = "http://101.43.182.203:9999/getResource?url=lincat/灵犀/lingxi.apk";
            ClipboardManager clip = (ClipboardManager)this.getSystemService(Context.CLIPBOARD_SERVICE);
            clip.setText(webUri); // 复制
            Toast.makeText(this, "安装包链接已经复制到剪切板RecordVO", Toast.LENGTH_SHORT).show();
        }
        return true;
    }
}
